<?php

class M_wechat extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function get_count($table,$where) {
        $this->db->from($table);
        $this->db->select('count(1) as cnt');
        $this->db->where($where);
        $result = $this->db->get()->row_array();
        return $result['cnt'];
    }

    function get_data_list($table,$data) {
        $this->db->from($table);
        if (isset($data['limit'])) {
            $this->db->limit($data['limit'], $data['offset']);
        }
        if(!empty($data['where'])){
            $this->db->where($data['where']);
        }
        if (isset($data['order'])) {
            $this->db->order_by($data['order']);
        }
        if (isset($data['column'])) {
            $this->db->select($data['column']);
        }
        $query = $this->db->get();
        return $query->result_array();
    }

    function get_data_multi($where, $num = '', $offset = ''){
        $this->db->select('weixinuser.*,weixingroup.groupname');
        $this->db->from('weixinuser');
        $this->db->join('weixingroup', 'weixinuser.groupid=weixingroup.groupid', 'left');
        $this->db->where($where);
        if ($num) {
            $this->db->limit($num, $offset);
        }
        $query = $this->db->get(); //echo $this->db->last_query();
        return $query->result_array();
    }

    function get_msgreply($where, $num = '', $offset = ''){
        $this->db->select('weixinmsgreply.*,admin.adminname');
        $this->db->from('weixinmsgreply');
        $this->db->join('admin','admin.adminid=weixinmsgreply.AdminID', 'left');
        $this->db->where($where);
        if(num){
            $this->db->limit($num, $offset);
        }
        $query = $this->db->get();
        return $query->result_array();
    }

}
